<!DOCTYPE html>
<html lang="en">
  <head>
    <title>String Extension Reference</title>
    <link rel="stylesheet" type="text/css" href="../css/jazzy.css" />
    <link rel="stylesheet" type="text/css" href="../css/highlight.css" />
    <meta charset="utf-8">
    <script src="../js/jquery.min.js" defer></script>
    <script src="../js/jazzy.js" defer></script>
    
    <script src="../js/lunr.min.js" defer></script>
    <script src="../js/typeahead.jquery.js" defer></script>
    <script src="../js/jazzy.search.js" defer></script>
  </head>
  <body>

    <a name="//apple_ref/swift/Extension/String" class="dashAnchor"></a>

    <a title="String Extension Reference"></a>

    <header class="header">
      <p class="header-col header-col--primary">
        <a class="header-link" href="../index.html">
          HTMLEntities 4.0.0 Docs
        </a>
         (100% documented)
      </p>
    
      <p class="header-col--secondary">
        <form role="search" action="../search.json">
          <input type="text" placeholder="Search documentation" data-typeahead>
        </form>
      </p>
    
        <p class="header-col header-col--secondary">
          <a class="header-link" href="https://github.com/Kitura/swift-html-entities">
            <img class="header-icon" src="../img/gh.png"/>
            View on GitHub
          </a>
        </p>
    
    </header>

    <p class="breadcrumbs">
      <a class="breadcrumb" href="../index.html">HTMLEntities Reference</a>
      <img class="carat" src="../img/carat.png" />
      String Extension Reference
    </p>

    <div class="content-wrapper">
      <nav class="navigation">
        <ul class="nav-groups">
          <li class="nav-group-name">
            <a class="nav-group-name-link" href="../Enums.html">Enumerations</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Enums/ParseError.html">ParseError</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a class="nav-group-name-link" href="../Extensions.html">Extensions</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Extensions/String.html">String</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Extensions/String/HTMLEscapeOptions.html">– HTMLEscapeOptions</a>
              </li>
            </ul>
          </li>
        </ul>
      </nav>
      <article class="main-content">

        <section class="section">
          <div class="section-content top-matter">
            <h1>String</h1>
              <div class="declaration">
                <div class="language">
                  
                  <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">extension</span> <span class="kt">String</span></code></pre>

                </div>
              </div>
            <p>This String extension provides utility functions to convert strings to their
HTML escaped equivalents and vice versa.</p>

          </div>
        </section>

        <section class="section">
          <div class="section-content">
            <div class="task-group">
              <ul class="item-container">
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:SS12HTMLEntitiesE17HTMLEscapeOptionsV"></a>
                    <a name="//apple_ref/swift/Struct/HTMLEscapeOptions" class="dashAnchor"></a>
                    <a class="token" href="#/s:SS12HTMLEntitiesE17HTMLEscapeOptionsV">HTMLEscapeOptions</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Global HTML escape options</p>

                        <a href="../Extensions/String/HTMLEscapeOptions.html" class="slightly-smaller">See more</a>
                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">struct</span> <span class="kt">HTMLEscapeOptions</span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:SS12HTMLEntitiesE10htmlEscape18allowUnsafeSymbols7decimal16encodeEverything18useNamedReferencesSSSb_S3btF"></a>
                    <a name="//apple_ref/swift/Method/htmlEscape(allowUnsafeSymbols:decimal:encodeEverything:useNamedReferences:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:SS12HTMLEntitiesE10htmlEscape18allowUnsafeSymbols7decimal16encodeEverything18useNamedReferencesSSSb_S3btF">htmlEscape(allowUnsafeSymbols:<wbr>decimal:<wbr>encodeEverything:<wbr>useNamedReferences:<wbr>)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Return string as HTML escaped by replacing non-ASCII and unsafe characters
with their numeric character escapes, or if such exists, their HTML named
character reference equivalents. For example, this function turns</p>

<p><code>&quot;&lt;script&gt;alert(&quot;abc&quot;)&lt;/script&gt;&quot;</code></p>

<p>into</p>

<p><code>&quot;&amp;lt;script&amp;gt;alert(&amp;quot;abc&amp;quot;)&amp;lt;/script&amp;gt;&quot;</code></p>

<p>You can view/change default option values globally via <code><a href="../Extensions/String/HTMLEscapeOptions.html">String.HTMLEscapeOptions</a></code>.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">func</span> <span class="nf">htmlEscape</span><span class="p">(</span><span class="nv">allowUnsafeSymbols</span><span class="p">:</span> <span class="kt">Bool</span> <span class="o">=</span> <span class="kt"><a href="../Extensions/String/HTMLEscapeOptions.html">HTMLEscapeOptions</a></span><span class="o">.</span><span class="n">allowUnsafeSymbols</span><span class="p">,</span>
                       <span class="nv">decimal</span><span class="p">:</span> <span class="kt">Bool</span> <span class="o">=</span> <span class="kt"><a href="../Extensions/String/HTMLEscapeOptions.html">HTMLEscapeOptions</a></span><span class="o">.</span><span class="n">decimal</span><span class="p">,</span>
                       <span class="nv">encodeEverything</span><span class="p">:</span> <span class="kt">Bool</span> <span class="o">=</span> <span class="kt"><a href="../Extensions/String/HTMLEscapeOptions.html">HTMLEscapeOptions</a></span><span class="o">.</span><span class="n">encodeEverything</span><span class="p">,</span>
                       <span class="nv">useNamedReferences</span><span class="p">:</span> <span class="kt">Bool</span> <span class="o">=</span> <span class="kt"><a href="../Extensions/String/HTMLEscapeOptions.html">HTMLEscapeOptions</a></span><span class="o">.</span><span class="n">useNamedReferences</span><span class="p">)</span>
    <span class="o">-&gt;</span> <span class="kt">String</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>allowUnsafeSymbols</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>Specifies if all ASCII characters should be skipped
when escaping text. <em>Optional</em></p>
                                </div>
                              </td>
                            </tr>
                            <tr>
                              <td>
                                <code>
                                <em>decimal</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>Specifies if decimal escapes should be used instead of
hexadecimal escapes. <em>Optional</em></p>
                                </div>
                              </td>
                            </tr>
                            <tr>
                              <td>
                                <code>
                                <em>encodeEverything</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>Specifies if all characters should be escaped, even if
some are safe characters. <em>Optional</em></p>
                                </div>
                              </td>
                            </tr>
                            <tr>
                              <td>
                                <code>
                                <em>useNamedReferences</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>Specifies if named character references
should be used whenever possible. <em>Optional</em></p>
                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:SS12HTMLEntitiesE12htmlUnescape6strictSSSb_tKF"></a>
                    <a name="//apple_ref/swift/Method/htmlUnescape(strict:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:SS12HTMLEntitiesE12htmlUnescape6strictSSSb_tKF">htmlUnescape(strict:<wbr>)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Return string as HTML unescaped by replacing HTML character references with their
unicode character equivalents. For example, this function turns</p>

<p><code>&quot;&amp;lt;script&amp;gt;alert(&amp;quot;abc&amp;quot;)&amp;lt;/script&amp;gt;&quot;</code></p>

<p>into</p>

<p><code>&quot;&lt;script&gt;alert(\&quot;abc\&quot;)&lt;/script&gt;&quot;</code></p>
<div class="aside aside-throws">
    <p class="aside-title">Throws</p>
    (Only if <code>strict == true</code>) The first <code><a href="../Enums/ParseError.html">ParseError</a></code> encountered during parsing.

</div>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">func</span> <span class="nf">htmlUnescape</span><span class="p">(</span><span class="nv">strict</span><span class="p">:</span> <span class="kt">Bool</span><span class="p">)</span> <span class="k">throws</span> <span class="o">-&gt;</span> <span class="kt">String</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>strict</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>Specifies if escapes MUST always end with <code>;</code>.</p>
                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:SS12HTMLEntitiesE12htmlUnescapeSSyF"></a>
                    <a name="//apple_ref/swift/Method/htmlUnescape()" class="dashAnchor"></a>
                    <a class="token" href="#/s:SS12HTMLEntitiesE12htmlUnescapeSSyF">htmlUnescape()</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Return string as HTML unescaped by replacing HTML character references with their
unicode character equivalents. For example, this function turns</p>

<p><code>&quot;&amp;lt;script&amp;gt;alert(&amp;quot;abc&amp;quot;)&amp;lt;/script&amp;gt;&quot;</code></p>

<p>into</p>

<p><code>&quot;&lt;script&gt;alert(\&quot;abc\&quot;)&lt;/script&gt;&quot;</code></p>

<p>Equivalent to <code>htmlUnescape(strict: false)</code>, but does NOT throw parse error.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">func</span> <span class="nf">htmlUnescape</span><span class="p">()</span> <span class="o">-&gt;</span> <span class="kt">String</span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
              </ul>
            </div>
          </div>
        </section>

      </article>
    </div>
    <section class="footer">
      <p>&copy; 2021 <a class="link" href="https://github.com/Kitura/swift-html-entities" target="_blank" rel="external">IBM and the Kitura project authors</a>. All rights reserved. (Last updated: 2021-08-28)</p>
      <p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.7</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
    </section>
  </body>
</div>
</html>
